package com.tbgov.interceptor;

import com.tbgov.service.TokenService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 注册拦截器
 *
 * @author 1st
 */
@Configuration
@RequiredArgsConstructor
public class WebConfig implements WebMvcConfigurer {

    final TokenService tokenService;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor(tokenService))
                // 拦截所有路径
                .addPathPatterns("/**")
                // 排除登录和静态资源
                .excludePathPatterns("/sso/login", "/sms/send", "/static/**", "/swagger-ui/**", "/v3/api-docs/**", "/**/auth/**");
    }
}
